import 'package:fluro/fluro.dart';
import 'package:flutter/cupertino.dart';

import '../ui/app_configuration/app_configuration.dart';
import '../ui/default/default_page.dart';
import '../ui/index/index.dart';
import '../ui/write_new/write_new.dart';

//路由出错的默认页面
var errorHandler = Handler(
    handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  return const DefaultPage();
});

//程序参数配置页面
var appConfigurationHandler = Handler(
    handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  return const AppConfigurationPage();
});

//主页面
var indexHandler = Handler(
    handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  return const IndexPage();
});

//写日记
var writeDiaryHandler = Handler(
    handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  if (params.isNotEmpty && params['id'] != null) {
    return WriteNewPage(id: params['id']![0]);
  } else {
    return const WriteNewPage(id: "");
  }
});

class Routes {
  static String indexPage = '/';
  static String errorPage = '/error';
  static String writeDiaryPage = '/writeDiary';
  static String appConfigurationPage = '/appConfiguration';

  static void configureRoutes(FluroRouter router) {
    router.define(errorPage, handler: errorHandler);
    router.define(appConfigurationPage, handler: appConfigurationHandler);
    router.define(indexPage, handler: indexHandler);
    router.define("$writeDiaryPage/:id", handler: writeDiaryHandler);
    router.notFoundHandler = errorHandler;
  }
}
